def pr(z):
    c = 0
    for i in range(2,z):
        if z % i == 0 :
            c+=1
    if c == 0: 
        return True
    else: 
        return False
    
            

ch=('zero' ,'one','two', 'three','four','five','six','seven','eight','nine')
s=input().split()
if len(s) == 3:
    if s[0] in ch and s[1] in ch and s[2] in ch :
        if s[0] != 'zero':
            a=ch.index(s[0])
            b=ch.index(s[1])
            c=ch.index(s[2])
            x=a*100 + b*10 + c
            for y in range(x,1, -1):
                if pr(y):
                    q=y
                    break
            for v in range(x,1010):
                if pr(v):
                    j=v
                    break
            if (x-q)>(j-x):
                print(q)
            else:
                print(j)

        else :
            print("Wrong input")
    else :
            print("Wrong input")
else :
            print("Wrong input")
            print("Wrong input")
else :
            print("Wrong input")